package com.time.admin.common.config;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 备份配置类
 *
 * @author: HuangQi
 * @date: Created in 16:33 2025/11/11
 * @description: 备份配置类
 */
@Data
@RefreshScope
@Component
@ConfigurationProperties(prefix = "blog.admin.backup")
public class BackupProperties {

    /**
     * 是否自动备份
     */
    private Boolean enabled = false;

    /**
     * 备份频率: DAILY, WEEKLY, MONTHLY
     */
    private Frequency frequency = Frequency.DAILY;

    /**
     * 保留备份次数
     */
    private Integer keepCount = 1;

    /**
     * 备份内容
     */
    private List<Content> contents;

    /**
     * 备份调度配置
     */
    private Schedule schedule = new Schedule();

    @Getter
    public enum Frequency {
        DAILY("day", "每日"),
        WEEKLY("week", "每周"),
        MONTHLY("month", "每月");

        public String name;

        public String desc;

        Frequency(String name, String desc) {
            this.name = name;
            this.desc = desc;
        }

        public static Frequency getByName(String nameVal) {
            for (Frequency frequency : Frequency.values()) {
                if (frequency.name.equals(nameVal)) {
                    return frequency;
                }
            }
            return null;
        }
    }

    @Getter
    public enum Content {
        DATABASE("database", "数据库"),
        FILES("files", "文件"),
        CONFIG("config", "配置文件");

        public String name;

        public String desc;

        Content(String name, String desc) {
            this.name = name;
            this.desc = desc;
        }

        public static Content getByName(String nameVal) {
            for (Content content : Content.values()) {
                if (content.name.equals(nameVal)) {
                    return content;
                }
            }
            return null;
        }
    }

    @Data
    public static class Schedule {
        private Weekly weekly = new Weekly();
        private Monthly monthly = new Monthly();

        @Data
        public static class Weekly {
            private String dayOfWeek = "SUNDAY";
            private String time = "00:00";
        }

        @Data
        public static class Monthly {
            private Integer dayOfMonth = 1;
            private String time = "00:00";
        }
    }
}
